%{
  #include "SkpReader.hpp"
  #include <SketchUp_i.h>
  #include <SketchUpAddin.h>
  #include <iostream>
%}

%include <stl.i>
%include <typemaps.i>
%include <std_except.i>

%exception {
  try {
    $action
  } catch (const std::exception& e) {
    rb_raise(rb_eRuntimeError, e.what());
  } catch (...) {
    rb_raise(rb_eRuntimeError, "Unknown C++ Runtime Error");
  }
}

// define the base template
template <class T> 
class SkpBase {
  public:
    SkpBase(T* impl)
      : m_impl(impl)
    {}
    T* getImpl() const
    {
      return m_impl;
    }
    bool isNull() const{
      return m_impl == NULL;
    }
  private:
    T* m_impl;
};

// instantiate templates
%template(SkpEntityProviderStatisticsBase) SkpBase<ISkpEntityProviderStatistics>;
%template(SkpFaceBase) SkpBase<ISkpFace>;
%template(SkpFacesBase) SkpBase<ISkpFaces>;
%template(SkpEntityProviderBase) SkpBase<ISkpEntityProvider>;
%template(SkpDocumentBase) SkpBase<ISkpDocument>;
%template(SkpFileReaderBase) SkpBase<ISkpFileReader>;
%template(SkpTextureWriterBase) SkpBase<ISkpTextureWriter>;
%template(SkpApplicationBase) SkpBase<ISkpApplication>;

// ignore definition of SkpBase in header
%ignore SkpBase;

// include header
%include "SkpReader.hpp"

